inherited fmRs_PreTabel: TfmRs_PreTabel
  Left = 523
  Top = 103
  Width = 994
  Height = 907
  Caption = #1055#1088#1077#1076#1074#1072#1088#1080#1090#1077#1083#1100#1085#1099#1081' '#1090#1072#1073#1077#1083#1100
  Constraints.MinHeight = 907
  Constraints.MinWidth = 994
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  inherited sbBottom: TStatusBar
    Top = 842
    Width = 978
  end
  inherited Panel1: TPanel
    Width = 978
    inherited BitBtn1: TBitBtn
      Left = 816
    end
    inherited BitBtn2: TBitBtn
      Left = 896
    end
  end
  object Panel2: TPanel [2]
    Left = 0
    Top = 45
    Width = 978
    Height = 64
    Align = alTop
    TabOrder = 2
    object Label13: TLabel
      Left = 11
      Top = 12
      Width = 106
      Height = 13
      Caption = #1044#1086#1087'. '#1087#1086#1076#1088#1072#1079#1076#1077#1083#1077#1085#1080#1077
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clGray
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
    end
    object tbFilterDeti: TcxButton
      Tag = 12
      Left = 664
      Top = 32
      Width = 105
      Height = 26
      Hint = #1048#1089#1082#1072#1090#1100
      Caption = #1048#1089#1082#1072#1090#1100
      ParentShowHint = False
      ShowHint = True
      TabOrder = 0
      TabStop = False
      Visible = False
      Glyph.Data = {
        76010000424D7601000000000000760000002800000020000000100000000100
        0400000000000001000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
        7777777777777777777777077777777777777787777777777777700077777777
        777778887777777777770F00077777777777878887777777777770F000777777
        77777878887777777777770F00078000877777878887F888F7777770F0008888
        807777787888FFFFF87777770007777778077777888777777F877777707777FF
        F78877777877777777FF777770777777FF707777787777777778777770777777
        7F7077777877777777787777788FF777777077777FF7777777787777788FF777
        777877777FF77777777F777778087777780777777F8F77777F87777777708888
        807777777778FFFFF877777777778000877777777777F888F777}
      LookAndFeel.SkinName = 'Blue'
      NumGlyphs = 2
    end
    object eDopPodrazd: TcxButtonEdit
      Tag = 10
      Left = 10
      Top = 31
      ParentFont = False
      Properties.Buttons = <
        item
          Glyph.Data = {
            F6000000424DF600000000000000760000002800000010000000100000000100
            0400000000008000000000000000000000001000000000000000000000000000
            8000008000000080800080000000800080008080000080808000C0C0C0000000
            FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
            FFFFFFFFFFF0FFFFFFFFFFFFFF000FFFFFFFFFFFF00000FFFFFFFFFF0000000F
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
        end>
      Properties.MaxLength = 0
      Properties.ReadOnly = True
      Properties.OnButtonClick = eDopPodrazdPropertiesButtonClick
      Style.Font.Charset = DEFAULT_CHARSET
      Style.Font.Color = clWindowText
      Style.Font.Height = -13
      Style.Font.Name = 'Tahoma'
      Style.Font.Style = [fsBold]
      Style.LookAndFeel.SkinName = ''
      Style.Shadow = False
      Style.IsFontAssigned = True
      StyleDisabled.LookAndFeel.SkinName = ''
      StyleFocused.LookAndFeel.SkinName = ''
      StyleHot.LookAndFeel.SkinName = ''
      TabOrder = 1
      Width = 407
    end
    object bAgrPrint: TcxButton
      Tag = 12
      Left = 423
      Top = 31
      Width = 231
      Height = 28
      Hint = ' '#1055#1077#1095#1072#1090#1100' '#1087#1088#1077#1076#1074#1072#1088#1080#1090#1077#1083#1100#1085#1086#1075#1086' '#1090#1072#1073#1077#1083#1103
      Caption = ' '#1055#1077#1095#1072#1090#1100' '#1087#1088#1077#1076#1074#1072#1088#1080#1090#1077#1083#1100#1085#1086#1075#1086' '#1090#1072#1073#1077#1083#1103
      ParentShowHint = False
      ShowHint = True
      TabOrder = 2
      TabStop = False
      OnClick = bAgrPrintClick
      Glyph.Data = {
        76010000424D7601000000000000760000002800000020000000100000000100
        04000000000000010000130B0000130B00001000000000000000000000000000
        800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00300000000000
        00033FFFFFFFFFFFFFFF0888888888888880777777777777777F088888888888
        8880777777777777777F0000000000000000FFFFFFFFFFFFFFFF0F8F8F8F8F8F
        8F80777777777777777F08F8F8F8F8F8F9F0777777777777777F0F8F8F8F8F8F
        8F807777777777777F7F0000000000000000777777777777777F3330FFFFFFFF
        03333337F3FFFF3F7F333330F0000F0F03333337F77773737F333330FFFFFFFF
        03333337F3FF3FFF7F333330F00F000003333337F773777773333330FFFF0FF0
        33333337F3FF7F3733333330F08F0F0333333337F7737F7333333330FFFF0033
        33333337FFFF7733333333300000033333333337777773333333}
      LookAndFeel.SkinName = 'Blue'
      NumGlyphs = 2
    end
  end
  object Panel3: TPanel [3]
    Left = 0
    Top = 109
    Width = 978
    Height = 229
    Align = alClient
    Caption = 'Panel3'
    TabOrder = 3
    object Label1: TLabel
      Left = 8
      Top = 6
      Width = 153
      Height = 13
      Caption = #1042#1086#1089#1087#1080#1090#1072#1085#1085#1080#1082#1080' '#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080':'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clGray
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
    end
    object cxGrid1: TcxGrid
      Left = 1
      Top = 24
      Width = 976
      Height = 204
      Align = alBottom
      Anchors = [akLeft, akTop, akRight, akBottom]
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -13
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      LookAndFeel.Kind = lfStandard
      object cxGridDBTableView1: TcxGridDBTableView
        NavigatorButtons.ConfirmDelete = False
        NavigatorButtons.PriorPage.Visible = True
        NavigatorButtons.Next.Visible = True
        NavigatorButtons.Insert.Visible = True
        NavigatorButtons.Append.Visible = False
        NavigatorButtons.Edit.Visible = False
        NavigatorButtons.Post.Visible = True
        NavigatorButtons.Cancel.Visible = False
        NavigatorButtons.Refresh.Visible = False
        NavigatorButtons.SaveBookmark.Visible = False
        NavigatorButtons.GotoBookmark.Visible = False
        NavigatorButtons.Filter.Visible = False
        DataController.DataSource = dsVospTerr
        DataController.Summary.DefaultGroupSummaryItems = <>
        DataController.Summary.FooterSummaryItems = <
          item
            Kind = skCount
            FieldName = 'PID'
          end>
        DataController.Summary.SummaryGroups = <>
        OptionsBehavior.CellHints = True
        OptionsCustomize.ColumnFiltering = False
        OptionsData.Appending = True
        OptionsData.CancelOnExit = False
        OptionsView.CellEndEllipsis = True
        OptionsView.NoDataToDisplayInfoText = '<'#1053#1077#1090' '#1076#1072#1085#1085#1099#1093'>'
        OptionsView.CellAutoHeight = True
        OptionsView.CellTextMaxLineCount = 1
        OptionsView.ColumnAutoWidth = True
        OptionsView.Footer = True
        OptionsView.GroupByBox = False
        OptionsView.HeaderEndEllipsis = True
        OptionsView.Indicator = True
        Preview.Visible = True
        Styles.Header = DMInv.cxSiniyText
        object cxGridDBTableView1PLASTNAME: TcxGridDBColumn
          Caption = #1060#1072#1084#1080#1083#1080#1103
          DataBinding.FieldName = 'PLASTNAME'
          Width = 236
        end
        object cxGridDBTableView1PNAME: TcxGridDBColumn
          Caption = #1048#1084#1103
          DataBinding.FieldName = 'PNAME'
          Width = 252
        end
        object cxGridDBTableView1OSNPODR: TcxGridDBColumn
          Caption = #1054#1089#1085'. '#1087#1086#1076#1088'.'
          DataBinding.FieldName = 'OSNPODR'
          Width = 193
        end
        object cxGridDBTableView1DOPDODR: TcxGridDBColumn
          Caption = #1044#1086#1087'. '#1087#1086#1076#1088'.'
          DataBinding.FieldName = 'DOPDODR'
          Width = 166
        end
        object cxGridDBTableView1KOLZAKAZ: TcxGridDBColumn
          Caption = #1047#1072#1082#1072#1079#1072#1085#1086
          DataBinding.FieldName = 'KOLZAKAZ'
          Width = 62
        end
        object cxGridDBTableView1KOLOKAZ: TcxGridDBColumn
          Caption = #1054#1082#1072#1079#1072#1085#1086
          DataBinding.FieldName = 'KOLOKAZ'
          Width = 59
        end
      end
      object cxGridLevel1: TcxGridLevel
        GridView = cxGridDBTableView1
      end
    end
  end
  object Panel4: TPanel [4]
    Left = 0
    Top = 338
    Width = 978
    Height = 252
    Align = alBottom
    Caption = 'Panel3'
    TabOrder = 4
    object Label2: TLabel
      Left = 8
      Top = 6
      Width = 168
      Height = 13
      Caption = #1042#1086#1089#1087#1080#1090#1072#1085#1085#1080#1082#1080' '#1085#1077' '#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080':'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clGray
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
    end
    object cxGrid2: TcxGrid
      Left = 1
      Top = 24
      Width = 976
      Height = 227
      Align = alBottom
      Anchors = [akLeft, akTop, akRight, akBottom]
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -13
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      LookAndFeel.Kind = lfStandard
      object cxGridDBTableView2: TcxGridDBTableView
        NavigatorButtons.ConfirmDelete = False
        NavigatorButtons.PriorPage.Visible = True
        NavigatorButtons.Next.Visible = True
        NavigatorButtons.Insert.Visible = True
        NavigatorButtons.Append.Visible = False
        NavigatorButtons.Edit.Visible = False
        NavigatorButtons.Post.Visible = True
        NavigatorButtons.Cancel.Visible = False
        NavigatorButtons.Refresh.Visible = False
        NavigatorButtons.SaveBookmark.Visible = False
        NavigatorButtons.GotoBookmark.Visible = False
        NavigatorButtons.Filter.Visible = False
        DataController.DataSource = dsVospNotTerr
        DataController.Summary.DefaultGroupSummaryItems = <>
        DataController.Summary.FooterSummaryItems = <
          item
            Kind = skCount
            FieldName = 'PID'
          end>
        DataController.Summary.SummaryGroups = <>
        OptionsBehavior.CellHints = True
        OptionsCustomize.ColumnFiltering = False
        OptionsData.Appending = True
        OptionsData.CancelOnExit = False
        OptionsView.CellEndEllipsis = True
        OptionsView.NoDataToDisplayInfoText = '<'#1053#1077#1090' '#1076#1072#1085#1085#1099#1093'>'
        OptionsView.CellAutoHeight = True
        OptionsView.CellTextMaxLineCount = 1
        OptionsView.ColumnAutoWidth = True
        OptionsView.Footer = True
        OptionsView.GroupByBox = False
        OptionsView.HeaderEndEllipsis = True
        OptionsView.Indicator = True
        Preview.Visible = True
        Styles.Header = DMInv.cxSiniyText
        object cxGridDBColumn1: TcxGridDBColumn
          Caption = #1060#1072#1084#1080#1083#1080#1103
          DataBinding.FieldName = 'PLASTNAME'
          Width = 236
        end
        object cxGridDBColumn2: TcxGridDBColumn
          Caption = #1048#1084#1103
          DataBinding.FieldName = 'PNAME'
          Width = 252
        end
        object cxGridDBColumn3: TcxGridDBColumn
          Caption = #1054#1089#1085'. '#1087#1086#1076#1088'.'
          DataBinding.FieldName = 'OSNPODR'
          Width = 193
        end
        object cxGridDBColumn4: TcxGridDBColumn
          Caption = #1044#1086#1087'. '#1087#1086#1076#1088'.'
          DataBinding.FieldName = 'DOPDODR'
          Width = 166
        end
        object cxGridDBColumn5: TcxGridDBColumn
          Caption = #1047#1072#1082#1072#1079#1072#1085#1086
          DataBinding.FieldName = 'KOLZAKAZ'
          Width = 62
        end
        object cxGridDBColumn6: TcxGridDBColumn
          Caption = #1054#1082#1072#1079#1072#1085#1086
          DataBinding.FieldName = 'KOLOKAZ'
          Width = 59
        end
      end
      object cxGridLevel2: TcxGridLevel
        GridView = cxGridDBTableView2
      end
    end
  end
  object Panel5: TPanel [5]
    Left = 0
    Top = 590
    Width = 978
    Height = 252
    Align = alBottom
    Caption = 'Panel3'
    TabOrder = 5
    object Label3: TLabel
      Left = 8
      Top = 6
      Width = 166
      Height = 13
      Caption = #1044#1077#1081#1089#1090#1074#1091#1102#1097#1080#1077' '#1076#1086#1087'. '#1089#1086#1075#1083#1072#1096#1077#1085#1080#1103':'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clGray
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
    end
    object cxGrid3: TcxGrid
      Left = 1
      Top = 24
      Width = 976
      Height = 227
      Align = alBottom
      Anchors = [akLeft, akTop, akRight, akBottom]
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -13
      Font.Name = 'Tahoma'
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      LookAndFeel.Kind = lfStandard
      object cxGridDBTableView3: TcxGridDBTableView
        NavigatorButtons.ConfirmDelete = False
        NavigatorButtons.PriorPage.Visible = True
        NavigatorButtons.Next.Visible = True
        NavigatorButtons.Insert.Visible = True
        NavigatorButtons.Append.Visible = False
        NavigatorButtons.Edit.Visible = False
        NavigatorButtons.Post.Visible = True
        NavigatorButtons.Cancel.Visible = False
        NavigatorButtons.Refresh.Visible = False
        NavigatorButtons.SaveBookmark.Visible = False
        NavigatorButtons.GotoBookmark.Visible = False
        NavigatorButtons.Filter.Visible = False
        DataController.DataSource = dsVospClose
        DataController.Summary.DefaultGroupSummaryItems = <>
        DataController.Summary.FooterSummaryItems = <
          item
            Kind = skCount
            FieldName = 'PID'
          end>
        DataController.Summary.SummaryGroups = <>
        OptionsBehavior.CellHints = True
        OptionsCustomize.ColumnFiltering = False
        OptionsData.Appending = True
        OptionsData.CancelOnExit = False
        OptionsView.CellEndEllipsis = True
        OptionsView.NoDataToDisplayInfoText = '<'#1053#1077#1090' '#1076#1072#1085#1085#1099#1093'>'
        OptionsView.CellAutoHeight = True
        OptionsView.CellTextMaxLineCount = 1
        OptionsView.ColumnAutoWidth = True
        OptionsView.Footer = True
        OptionsView.GroupByBox = False
        OptionsView.HeaderEndEllipsis = True
        OptionsView.Indicator = True
        Preview.Visible = True
        Styles.Header = DMInv.cxSiniyText
        object cxGridDBColumn7: TcxGridDBColumn
          Caption = #1060#1072#1084#1080#1083#1080#1103
          DataBinding.FieldName = 'PLASTNAME'
          Width = 236
        end
        object cxGridDBColumn8: TcxGridDBColumn
          Caption = #1048#1084#1103
          DataBinding.FieldName = 'PNAME'
          Width = 252
        end
        object cxGridDBColumn9: TcxGridDBColumn
          Caption = #1054#1089#1085'. '#1087#1086#1076#1088'.'
          DataBinding.FieldName = 'OSNPODR'
          Width = 193
        end
        object cxGridDBColumn10: TcxGridDBColumn
          Caption = #1044#1086#1087'. '#1087#1086#1076#1088'.'
          DataBinding.FieldName = 'DOPDODR'
          Width = 166
        end
        object cxGridDBColumn11: TcxGridDBColumn
          Caption = #1047#1072#1082#1072#1079#1072#1085#1086
          DataBinding.FieldName = 'KOLZAKAZ'
          Width = 62
        end
        object cxGridDBColumn12: TcxGridDBColumn
          Caption = #1054#1082#1072#1079#1072#1085#1086
          DataBinding.FieldName = 'KOLOKAZ'
          Width = 59
        end
      end
      object cxGridLevel3: TcxGridLevel
        GridView = cxGridDBTableView3
      end
    end
  end
  object dsVospTerr: TDataSource
    DataSet = qVospTerr
    Left = 160
    Top = 184
  end
  object qVospTerr: TIBQuery
    Database = DMInv.DBRead
    Transaction = DMInv.IBTransaction1
    CachedUpdates = True
    DataSource = dlgDS
    SQL.Strings = (
      'select *'
      
        'from (select L.STID, L.SDID, iif(IND.SDID is null,0,1) as indivi' +
        'd, DP.SDNAME as DOPDODR, S.SCID, K.PID,'
      
        '             sum(iif(K.KOLZAKAZ is null, 0, 1)) as KOLZAKAZ, sum' +
        '(iif(K.KOLOKAZ is null, 0, 1)) as KOLOKAZ,'
      
        '             ST.STISOUTTER, SO.SDNAME as OSNPODR, PV.PID as TERR' +
        ', P.PLASTNAME, P.PNAME,'
      '             case'
      '               when sum(K.KOLOKAZ) >= sum(K.KOLZAKAZ) then 1'
      '               else 0'
      '             end as OKAZ'
      '      from SERV_PODR_LINK L'
      '      left join(select T1.SDID'
      
        '                from (with recursive TREE (SDNAME, SDID, SDPARID' +
        ') as (select SD.SDNAME, SD.SDID, SD.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD'
      
        '                                                                ' +
        '      where SD.SDPARID = 2130'
      
        '                                                                ' +
        '      union all'
      
        '                                                                ' +
        '      select SD1.SDNAME, SD1.SDID, SD1.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD1'
      
        '                                                                ' +
        '      inner join TREE T on T.SDID = SD1.SDPARID) select SDNAME,'
      
        '                                                                ' +
        '                                                        SDID,'
      
        '                                                                ' +
        '                                                        SDPARID'
      
        '                                                                ' +
        '                                                 from TREE T) as' +
        ' T1'
      '                order by 1) IND on IND.SDID = L.SDID'
      '      inner join SYS_DIC DP on DP.SDID = L.SDID'
      '      inner join SERVICES S on S.STID = L.STID'
      '      inner join TMP_KOLDOPUSLUG K on K.SCID = S.SCID'
      '      inner join PEOPLE P on P.PID = K.PID'
      
        '      inner join DETI_PODRAZD OP on OP.PID = P.PID and current_d' +
        'ate between cast(OP.DPDATEIN as date) and coalesce(cast(OP.DPDAT' +
        'EOUT as date), current_date + 3650)'
      '      inner join SYS_DIC SO on SO.SDID = OP.SDID'
      '      left join SERVICES_TYPE ST on ST.STID = L.STID'
      '      left join(select *'
      '                from P_VIZIT PV1'
      
        '                where current_timestamp between PV1.PVTIME_IN an' +
        'd PV1.PVTIME_OUT) PV on PV.PID = P.PID'
      '      where L.SDID in (:SDID) and'
      '            current_date between K.DATEBEGIN and K.DATEEND'
      '      group by 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13'
      '      order by OSNPODR, P.PLASTNAME, P.PNAME) VOSP'
      
        'where KOLZAKAZ > KOLOKAZ and ((terr is not null) or (STISOUTTER=' +
        '1)  )'
      ''
      '  ')
    Left = 192
    Top = 184
    ParamData = <
      item
        DataType = ftString
        Name = 'SDID'
        ParamType = ptUnknown
        Value = '13350'
      end>
    object qVospTerrSTID: TIntegerField
      FieldName = 'STID'
      ProviderFlags = []
    end
    object qVospTerrSDID: TIntegerField
      FieldName = 'SDID'
      ProviderFlags = []
    end
    object qVospTerrINDIVID: TIntegerField
      FieldName = 'INDIVID'
      ProviderFlags = []
    end
    object qVospTerrDOPDODR: TIBStringField
      FieldName = 'DOPDODR'
      ProviderFlags = []
      Size = 255
    end
    object qVospTerrSCID: TIntegerField
      FieldName = 'SCID'
      ProviderFlags = []
    end
    object qVospTerrPID: TIntegerField
      FieldName = 'PID'
      ProviderFlags = []
    end
    object qVospTerrKOLZAKAZ: TLargeintField
      FieldName = 'KOLZAKAZ'
      ProviderFlags = []
    end
    object qVospTerrKOLOKAZ: TLargeintField
      FieldName = 'KOLOKAZ'
      ProviderFlags = []
    end
    object qVospTerrSTISOUTTER: TIntegerField
      FieldName = 'STISOUTTER'
      ProviderFlags = []
    end
    object qVospTerrOSNPODR: TIBStringField
      FieldName = 'OSNPODR'
      ProviderFlags = []
      Size = 255
    end
    object qVospTerrTERR: TIntegerField
      FieldName = 'TERR'
      ProviderFlags = []
    end
    object qVospTerrPLASTNAME: TIBStringField
      FieldName = 'PLASTNAME'
      ProviderFlags = []
      Size = 255
    end
    object qVospTerrPNAME: TIBStringField
      FieldName = 'PNAME'
      ProviderFlags = []
      Size = 255
    end
    object qVospTerrOKAZ: TIntegerField
      FieldName = 'OKAZ'
      ProviderFlags = []
    end
  end
  object frReportIND: TfrxReport
    Version = '4.9'
    DotMatrixReport = False
    IniFile = '\Software\Fast Reports'
    PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
    PreviewOptions.Zoom = 1.000000000000000000
    PrintOptions.Printer = 'Default'
    PrintOptions.PrintOnSheet = 0
    ReportOptions.CreateDate = 41176.642275324100000000
    ReportOptions.LastChange = 41185.745789745400000000
    ScriptLanguage = 'PascalScript'
    StoreInDFM = False
    Left = 491
    Top = 140
  end
  object dsVospNotTerr: TDataSource
    DataSet = qVospNotTerr
    Left = 160
    Top = 432
  end
  object qVospNotTerr: TIBQuery
    Database = DMInv.DBRead
    Transaction = DMInv.IBTransaction1
    CachedUpdates = True
    DataSource = dlgDS
    SQL.Strings = (
      'select *'
      
        'from (select L.STID, L.SDID, IND.SDID as INDIVID, DP.SDNAME as D' +
        'OPDODR, S.SCID, K.PID,'
      
        '             sum(iif(K.KOLZAKAZ is null, 0, 1)) as KOLZAKAZ, sum' +
        '(iif(K.KOLOKAZ is null, 0, 1)) as KOLOKAZ,'
      
        '             ST.STISOUTTER, SO.SDNAME as OSNPODR, PV.PID as TERR' +
        ', P.PLASTNAME, P.PNAME,'
      '             case'
      '               when sum(K.KOLOKAZ) >= sum(K.KOLZAKAZ) then 1'
      '               else 0'
      '             end as OKAZ'
      '      from SERV_PODR_LINK L'
      '      left join(select T1.SDID'
      
        '                from (with recursive TREE (SDNAME, SDID, SDPARID' +
        ') as (select SD.SDNAME, SD.SDID, SD.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD'
      
        '                                                                ' +
        '      where SD.SDPARID = 2130'
      
        '                                                                ' +
        '      union all'
      
        '                                                                ' +
        '      select SD1.SDNAME, SD1.SDID, SD1.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD1'
      
        '                                                                ' +
        '      inner join TREE T on T.SDID = SD1.SDPARID) select SDNAME,'
      
        '                                                                ' +
        '                                                        SDID,'
      
        '                                                                ' +
        '                                                        SDPARID'
      
        '                                                                ' +
        '                                                 from TREE T) as' +
        ' T1'
      '                order by 1) IND on IND.SDID = L.SDID'
      '      inner join SYS_DIC DP on DP.SDID = L.SDID'
      '      inner join SERVICES S on S.STID = L.STID'
      '      inner join TMP_KOLDOPUSLUG K on K.SCID = S.SCID'
      '      inner join PEOPLE P on P.PID = K.PID'
      
        '      inner join DETI_PODRAZD OP on OP.PID = P.PID and current_d' +
        'ate between cast(OP.DPDATEIN as date) and coalesce(cast(OP.DPDAT' +
        'EOUT as date), current_date + 3650)'
      '      inner join SYS_DIC SO on SO.SDID = OP.SDID'
      '      left join SERVICES_TYPE ST on ST.STID = L.STID'
      '      left join(select *'
      '                from P_VIZIT PV1'
      
        '                where current_timestamp between PV1.PVTIME_IN an' +
        'd PV1.PVTIME_OUT) PV on PV.PID = P.PID'
      '      where L.SDID in (:SDID) and'
      '            current_date between K.DATEBEGIN and K.DATEEND'
      '      group by 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13'
      '      order by OSNPODR, P.PLASTNAME, P.PNAME) VOSP'
      
        'where KOLZAKAZ > KOLOKAZ and ((terr is not null) or (STISOUTTER=' +
        '1)  )'
      ''
      '  ')
    Left = 192
    Top = 432
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'SDID'
        ParamType = ptUnknown
      end>
    object qVospNotTerrSTID: TIntegerField
      FieldName = 'STID'
      ProviderFlags = []
    end
    object qVospNotTerrSDID: TIntegerField
      FieldName = 'SDID'
      ProviderFlags = []
    end
    object qVospNotTerrINDIVID: TIntegerField
      FieldName = 'INDIVID'
      ProviderFlags = []
    end
    object qVospNotTerrDOPDODR: TIBStringField
      FieldName = 'DOPDODR'
      ProviderFlags = []
      Size = 255
    end
    object qVospNotTerrSCID: TIntegerField
      FieldName = 'SCID'
      ProviderFlags = []
    end
    object qVospNotTerrPID: TIntegerField
      FieldName = 'PID'
      ProviderFlags = []
    end
    object qVospNotTerrKOLZAKAZ: TLargeintField
      FieldName = 'KOLZAKAZ'
      ProviderFlags = []
    end
    object qVospNotTerrKOLOKAZ: TLargeintField
      FieldName = 'KOLOKAZ'
      ProviderFlags = []
    end
    object qVospNotTerrSTISOUTTER: TIntegerField
      FieldName = 'STISOUTTER'
      ProviderFlags = []
    end
    object qVospNotTerrOSNPODR: TIBStringField
      FieldName = 'OSNPODR'
      ProviderFlags = []
      Size = 255
    end
    object qVospNotTerrTERR: TIntegerField
      FieldName = 'TERR'
      ProviderFlags = []
    end
    object qVospNotTerrPLASTNAME: TIBStringField
      FieldName = 'PLASTNAME'
      ProviderFlags = []
      Size = 255
    end
    object qVospNotTerrPNAME: TIBStringField
      FieldName = 'PNAME'
      ProviderFlags = []
      Size = 255
    end
    object qVospNotTerrOKAZ: TIntegerField
      FieldName = 'OKAZ'
      ProviderFlags = []
    end
  end
  object dsVospClose: TDataSource
    DataSet = qVospClose
    Left = 160
    Top = 680
  end
  object qVospClose: TIBQuery
    Database = DMInv.DBRead
    Transaction = DMInv.IBTransaction1
    CachedUpdates = True
    DataSource = dlgDS
    SQL.Strings = (
      'select *'
      
        'from (select L.STID, L.SDID, IND.SDID as INDIVID, DP.SDNAME as D' +
        'OPDODR, S.SCID, K.PID,'
      
        '             sum(iif(K.KOLZAKAZ is null, 0, 1)) as KOLZAKAZ, sum' +
        '(iif(K.KOLOKAZ is null, 0, 1)) as KOLOKAZ,'
      
        '             ST.STISOUTTER, SO.SDNAME as OSNPODR, PV.PID as TERR' +
        ', P.PLASTNAME, P.PNAME,'
      '             case'
      '               when sum(K.KOLOKAZ) >= sum(K.KOLZAKAZ) then 1'
      '               else 0'
      '             end as OKAZ'
      '      from SERV_PODR_LINK L'
      '      left join(select T1.SDID'
      
        '                from (with recursive TREE (SDNAME, SDID, SDPARID' +
        ') as (select SD.SDNAME, SD.SDID, SD.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD'
      
        '                                                                ' +
        '      where SD.SDPARID = 2130'
      
        '                                                                ' +
        '      union all'
      
        '                                                                ' +
        '      select SD1.SDNAME, SD1.SDID, SD1.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD1'
      
        '                                                                ' +
        '      inner join TREE T on T.SDID = SD1.SDPARID) select SDNAME,'
      
        '                                                                ' +
        '                                                        SDID,'
      
        '                                                                ' +
        '                                                        SDPARID'
      
        '                                                                ' +
        '                                                 from TREE T) as' +
        ' T1'
      '                order by 1) IND on IND.SDID = L.SDID'
      '      inner join SYS_DIC DP on DP.SDID = L.SDID'
      '      inner join SERVICES S on S.STID = L.STID'
      '      inner join TMP_KOLDOPUSLUG K on K.SCID = S.SCID'
      '      inner join PEOPLE P on P.PID = K.PID'
      
        '      inner join DETI_PODRAZD OP on OP.PID = P.PID and current_d' +
        'ate between cast(OP.DPDATEIN as date) and coalesce(cast(OP.DPDAT' +
        'EOUT as date), current_date + 3650)'
      '      inner join SYS_DIC SO on SO.SDID = OP.SDID'
      '      left join SERVICES_TYPE ST on ST.STID = L.STID'
      '      left join(select *'
      '                from P_VIZIT PV1'
      
        '                where current_timestamp between PV1.PVTIME_IN an' +
        'd PV1.PVTIME_OUT) PV on PV.PID = P.PID'
      '      where L.SDID in (:SDID) and'
      '            current_date between K.DATEBEGIN and K.DATEEND'
      '      group by 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13'
      '      order by OSNPODR, P.PLASTNAME, P.PNAME) VOSP'
      
        'where KOLZAKAZ > KOLOKAZ and ((terr is not null) or (STISOUTTER=' +
        '1)  )'
      ''
      '  ')
    Left = 192
    Top = 680
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'SDID'
        ParamType = ptUnknown
      end>
    object qVospCloseSTID: TIntegerField
      FieldName = 'STID'
      ProviderFlags = []
    end
    object qVospCloseSDID: TIntegerField
      FieldName = 'SDID'
      ProviderFlags = []
    end
    object qVospCloseINDIVID: TIntegerField
      FieldName = 'INDIVID'
      ProviderFlags = []
    end
    object qVospCloseDOPDODR: TIBStringField
      FieldName = 'DOPDODR'
      ProviderFlags = []
      Size = 255
    end
    object qVospCloseSCID: TIntegerField
      FieldName = 'SCID'
      ProviderFlags = []
    end
    object qVospClosePID: TIntegerField
      FieldName = 'PID'
      ProviderFlags = []
    end
    object qVospCloseKOLZAKAZ: TLargeintField
      FieldName = 'KOLZAKAZ'
      ProviderFlags = []
    end
    object qVospCloseKOLOKAZ: TLargeintField
      FieldName = 'KOLOKAZ'
      ProviderFlags = []
    end
    object qVospCloseSTISOUTTER: TIntegerField
      FieldName = 'STISOUTTER'
      ProviderFlags = []
    end
    object qVospCloseOSNPODR: TIBStringField
      FieldName = 'OSNPODR'
      ProviderFlags = []
      Size = 255
    end
    object qVospCloseTERR: TIntegerField
      FieldName = 'TERR'
      ProviderFlags = []
    end
    object qVospClosePLASTNAME: TIBStringField
      FieldName = 'PLASTNAME'
      ProviderFlags = []
      Size = 255
    end
    object qVospClosePNAME: TIBStringField
      FieldName = 'PNAME'
      ProviderFlags = []
      Size = 255
    end
    object qVospCloseOKAZ: TIntegerField
      FieldName = 'OKAZ'
      ProviderFlags = []
    end
  end
  object frReportGR: TfrxReport
    Version = '4.9'
    DotMatrixReport = False
    IniFile = '\Software\Fast Reports'
    PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
    PreviewOptions.Zoom = 1.000000000000000000
    PrintOptions.Printer = 'Default'
    PrintOptions.PrintOnSheet = 0
    ReportOptions.CreateDate = 41176.642275324100000000
    ReportOptions.LastChange = 41193.721139247680000000
    ScriptLanguage = 'PascalScript'
    StoreInDFM = False
    Left = 491
    Top = 172
  end
  object qDoppodr: TIBQuery
    Database = DMInv.DBRead
    Transaction = DMInv.IBTransaction1
    CachedUpdates = True
    DataSource = dlgDS
    SQL.Strings = (
      'select * from (select VOSP.*,'
      '    case'
      
        '        when (VOSP.KOLZAKAZ > VOSP.KOLOKAZ) and ((VOSP.terr is n' +
        'ot null) or (VOSP.STISOUTTER=1))'
      '        then 1'
      
        '         when (VOSP.KOLZAKAZ > VOSP.KOLOKAZ) and (VOSP.terr is n' +
        'ull) and (VOSP.STISOUTTER<>1)'
      '        then 2'
      '         when (VOSP.KOLZAKAZ <= VOSP.KOLOKAZ)'
      '        then 3'
      '   end as str,'
      '   case'
      
        '        when (VOSP.KOLZAKAZ > VOSP.KOLOKAZ) and ((VOSP.terr is n' +
        'ot null) or (VOSP.STISOUTTER=1))'
      '        then '#39#1086#1089#1085#1086#1074#1085#1086#1081' '#1089#1087#1080#1089#1086#1082#39
      
        '         when (VOSP.KOLZAKAZ > VOSP.KOLOKAZ) and (VOSP.terr is n' +
        'ull) and (VOSP.STISOUTTER<>1)'
      '        then '#39#1085#1077' '#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080#39
      '         when (VOSP.KOLZAKAZ <= VOSP.KOLOKAZ)'
      '        then '#39#1086#1082#1072#1079#1072#1085#1085#1099#1077' '#1085#1077' '#1074' '#1087#1086#1083#1085#1086#1084' '#1086#1073#1098#1077#1084#1077#39
      '        else 0'
      '   end as str2'
      ''
      
        'from (select L.STID, L.SDID, iif(IND.SDID is null, 0, 1) as INDI' +
        'VID, DP.SDNAME as DOPDODR, S.SCID, K.PID,'
      
        '             sum(iif(K.KOLZAKAZ is null, 0, K.KOLZAKAZ)) as KOLZ' +
        'AKAZ,'
      
        '             sum(iif(K.KOLOKAZ is null, 0, K.KOLOKAZ)) as KOLOKA' +
        'Z, iif(ST.STISOUTTER is null, 0, 1) as STISOUTTER,'
      
        '             SO.SDNAME as OSNPODR, PV.PID as TERR, P.PLASTNAME, ' +
        'P.PNAME,'
      '             case'
      '               when sum(K.KOLOKAZ) >= sum(K.KOLZAKAZ) then 1'
      '               else 0'
      '             end as OKAZ'
      '      from SERV_PODR_LINK L'
      '      left join(select T1.SDID'
      
        '                from (with recursive TREE (SDNAME, SDID, SDPARID' +
        ') as (select SD.SDNAME, SD.SDID, SD.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD'
      
        '                                                                ' +
        '      where SD.SDPARID = 2130'
      
        '                                                                ' +
        '      union all'
      
        '                                                                ' +
        '      select SD1.SDNAME, SD1.SDID, SD1.SDPARID'
      
        '                                                                ' +
        '      from SYS_DIC SD1'
      
        '                                                                ' +
        '      inner join TREE T on T.SDID = SD1.SDPARID) select SDNAME,'
      
        '                                                                ' +
        '                                                        SDID,'
      
        '                                                                ' +
        '                                                        SDPARID'
      
        '                                                                ' +
        '                                                 from TREE T) as' +
        ' T1'
      '                order by 1) IND on IND.SDID = L.SDID'
      '      inner join SYS_DIC DP on DP.SDID = L.SDID'
      '      inner join SERVICES S on S.STID = L.STID'
      '      inner join TMP_KOLDOPUSLUG K on K.SCID = S.SCID'
      '      left join PEOPLE P on P.PID = K.PID'
      
        '      inner join DETI_PODRAZD OP on OP.PID = P.PID and current_d' +
        'ate between cast(OP.DPDATEIN as date) and coalesce(cast(OP.DPDAT' +
        'EOUT as date), current_date + 3650)'
      
        '      inner join DETI_PODRAZD_MISC DM on DM.SDID = DP.SDID and P' +
        '.PID = DM.PID and current_date between cast(DM.DPDATEIN as date)' +
        ' and coalesce(cast(DM.DPDATEOUT as date), current_date + 3650)'
      '      inner join SYS_DIC SO on SO.SDID = OP.SDID'
      '      left join SERVICES_TYPE ST on ST.STID = L.STID'
      '      left join(select *'
      '                from P_VIZIT PV1'
      
        '                where current_timestamp between PV1.PVTIME_IN an' +
        'd PV1.PVTIME_OUT) PV on PV.PID = P.PID'
      
        '      where (L.SDID in (1850, 1851, 1852, 2004, 2005, 11957)) an' +
        'd'
      '            (current_date between K.DATEBEGIN and K.DATEEND)'
      '      group by 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13'
      
        '      order by DOPDODR, OSNPODR, P.PLASTNAME, P.PNAME) VOSP ) so' +
        'rts'
      'order by DOPDODR, str, OSNPODR, PLASTNAME, PNAME')
    Left = 440
    Top = 152
    object qDoppodrSTID: TIntegerField
      FieldName = 'STID'
      ProviderFlags = []
    end
    object qDoppodrSDID: TIntegerField
      FieldName = 'SDID'
      ProviderFlags = []
    end
    object qDoppodrINDIVID: TIntegerField
      FieldName = 'INDIVID'
      ProviderFlags = []
    end
    object qDoppodrDOPDODR: TIBStringField
      FieldName = 'DOPDODR'
      ProviderFlags = []
      Size = 255
    end
    object qDoppodrSCID: TIntegerField
      FieldName = 'SCID'
      ProviderFlags = []
    end
    object qDoppodrPID: TIntegerField
      FieldName = 'PID'
      ProviderFlags = []
    end
    object qDoppodrKOLZAKAZ: TLargeintField
      FieldName = 'KOLZAKAZ'
      ProviderFlags = []
    end
    object qDoppodrKOLOKAZ: TLargeintField
      FieldName = 'KOLOKAZ'
      ProviderFlags = []
    end
    object qDoppodrSTISOUTTER: TIntegerField
      FieldName = 'STISOUTTER'
      ProviderFlags = []
    end
    object qDoppodrOSNPODR: TIBStringField
      FieldName = 'OSNPODR'
      ProviderFlags = []
      Size = 255
    end
    object qDoppodrTERR: TIntegerField
      FieldName = 'TERR'
      ProviderFlags = []
    end
    object qDoppodrPLASTNAME: TIBStringField
      FieldName = 'PLASTNAME'
      ProviderFlags = []
      Size = 255
    end
    object qDoppodrPNAME: TIBStringField
      FieldName = 'PNAME'
      ProviderFlags = []
      Size = 255
    end
    object qDoppodrOKAZ: TIntegerField
      FieldName = 'OKAZ'
      ProviderFlags = []
    end
    object qDoppodrSTR: TIntegerField
      FieldName = 'STR'
      ProviderFlags = []
    end
    object qDoppodrSTR2: TIBStringField
      FieldName = 'STR2'
      ProviderFlags = []
      Size = 28
    end
  end
  object dsDoppodr: TDataSource
    DataSet = qDoppodr
    Left = 408
    Top = 152
  end
  object frDoppodr: TfrxDBDataset
    UserName = 'Doppodr'
    CloseDataSource = False
    FieldAliases.Strings = (
      'STID=STID'
      'SDID=SDID'
      'INDIVID=INDIVID'
      'DOPDODR=DOPDODR'
      'SCID=SCID'
      'PID=PID'
      'KOLZAKAZ=KOLZAKAZ'
      'KOLOKAZ=KOLOKAZ'
      'STISOUTTER=STISOUTTER'
      'OSNPODR=OSNPODR'
      'TERR=TERR'
      'PLASTNAME=PLASTNAME'
      'PNAME=PNAME'
      'OKAZ=OKAZ'
      'STR=STR'
      'STR2=STR2')
    DataSet = qDoppodr
    BCDToCurrency = False
    Left = 524
    Top = 140
  end
end
